#include "lcoinwidget.h"

LCoinWidget::LCoinWidget ( QWidget *parent, Qt::WFlags f) {
    LCoinWidget(parent, f, LCoinWidget::Slag);
}

LCoinWidget::LCoinWidget ( QWidget *parent, Qt::WFlags f, int coinType) {
    QHBoxLayout *layout = new QHBoxLayout(this);
    layout->setMargin(2);
    layout->setSpacing(0);
    layout->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
    setType(coinType);
    tdisplay = new QLabel(QString("%1:  ").arg(text()), this);
    tdisplay->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    layout->addWidget(tdisplay);
        
    ndisplay = new QSpinBox(this);
    ndisplay->setMaximum(5000);
    layout->addWidget(ndisplay);
    setValue(0);
    setMaximumHeight(40);
    ndisplay->setAlignment(Qt::AlignRight);
    connect (ndisplay, SIGNAL(valueChanged(int)), 
        this, SLOT(slotValueChanged(int)));
    ndisplay->setFocusPolicy(Qt::NoFocus);

    m_parent = parent;
    m_flags = f;
}

QString LCoinWidget::text() const {
    switch (type()) {
        case Orb:
            return "Orb";
        case Crown:
            return "Crown";
        case Danar:
            return "Danar";
        case Slag:
            return "Slag";
    }
    return "Slag";
}

int LCoinWidget::type() const {
    if(m_cointype > Orb || m_cointype < Slag) return Slag;
    return m_cointype;
}

void LCoinWidget::setType(int type) {
    m_cointype = type;
}

void LCoinWidget::setValue(int i) {
    m_value = i;
    ndisplay->setValue(value());
}

int LCoinWidget::value() const {
    return m_value;
}

int LCoinWidget::slagValue() const {
    switch (type()) {
        case Orb:
            return value() * 1000;
        case Crown:
            return value() * 100;
        case Danar:
            return value() * 10;
        case Slag:
            return value() * 1;
    }
    return value() * 1;
}

void LCoinWidget::add(int i) {
    m_value += i;
    ndisplay->setValue(value());
    emit(valueChanged());
}

void LCoinWidget::slotValueChanged(int val) {
    m_value = val;
//    QMessageBox::information(this, "Looter", "slotValueChanged()");
    emit(valueChanged());
}
